package com.zy.web.controller.bs;

import com.zy.pojo.query.crm.CustomerApplyQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.CustomerApply;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.CustomerApplyService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/customerApply","m/bs/customerApply"})
@Controller
public class CustomerApplyController extends BaseController {

	@Autowired
	private CustomerApplyService customerApplyService;

	/**
	 * 分页
 	 * 
 	 * @param customerApplyQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageCustomerApply")
	@ResponseBody
	public PageVo pageCustomerApply(CustomerApplyQuery customerApplyQuery, Integer start, Integer limit) {
		return this.customerApplyService.pageCustomerApply(customerApplyQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param customerApply
	 * @return
	 */
	@RequestMapping(value = "saveCustomerApply", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveCustomerApply(CustomerApply customerApply) {
		try {
			this.customerApplyService.saveCustomerApply(customerApply);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param customerApply
	 * @return
	 */
	@RequestMapping(value = "updateCustomerApply", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateCustomerApply(CustomerApply customerApply) {
		try {
			this.customerApplyService.updateCustomerApply(customerApply);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeCustomerApply", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeCustomerApply(long id) {
		try {
			this.customerApplyService.removeCustomerApply(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.customerApplyService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

    @RequestMapping(value = "registCustomerApply", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo registCustomerApply(CustomerApply customerApply) {
        try {
            customerApply.setCustomerId(this.getCurrentCustomer().getId());
            this.customerApplyService.regiestCustomerApply(customerApply);
            return ResultUtil.success();
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }

    @RequestMapping(value = "getCustomerApply")
    @ResponseBody
    public ResultVo getCustomerApply(Long clubId) {
        try {
            return ResultUtil.success(this.customerApplyService.getCheckWait(clubId));
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }
    @RequestMapping(value = "checkCustomerApply", method = RequestMethod.POST)
    @ResponseBody
    public ResultVo checkCustomerApply(CustomerApply customerApply) {
        try {

            this.customerApplyService.checkCustomerApply(customerApply);
            return ResultUtil.success();
        } catch (Exception e) {
            return ResultUtil.error(log, e);
        }
    }

}